<div [@routerTransition]>
  <div class="m-subheader">
    <div class="d-flex align-items-center">
      <div class="mr-auto col-xs-6">
        <h3 class="m-subheader__title m-subheader__title--separator">
          <span>月度计划</span>
        </h3>
        <span class="m-section__sub"> 管理月度计划的文本头信息 </span>
      </div>
      <div class="col-xs-6 text-right">
        <button
          (click)="importMonthOrders()"
          *ngIf="permission.isGranted('Pages.Plan.Month.Import')"
          class="btn btn-success green"
          [buttonBusy]="anyncing"
          [busyText]="'同步中...'"
        >
          <i class="fa fa-refresh"></i> 同步月度计划
        </button>
      </div>
    </div>
  </div>
  <div class="m-content">
    <div class="m-portlet m-portlet--mobile">
      <div class="m-portlet__body">
        <div class="tabbable-line">
          <ul class="nav nav-tabs m-tabs-line">
            <li *ngFor="let tab of tabs" class="nav-item m-tabs__item">
              <a
                href="#tab-model"
                data-toggle="tab"
                class="nav-link m-tabs__link"
                (click)="tabTypeClick(tab.tabType.value)"
                [ngClass]="{ active: tab.tabType.isSelected }"
              >
                {{ tab.tabType.displayText }}
                <span class="badge {{ tab.tabBadgeColor }}">{{
                  tab.tabBadgeCount
                }}</span>
              </a>
            </li>
            <div style="width: 200px; display: inline-block; margin-left: 40px">
              <p-calendar
                (click)="getTabs()"
                [(ngModel)]="planDate"
                view="month"
                dateFormat="yy-mm"
                [showIcon]="true"
                name="planDate"
                [inputStyle]="{ width: '126px' }"
              ></p-calendar>
            </div>
          </ul>
          <div class="tab-content" style="padding-top: 0">
            <div class="tab-pane active" id="tab-model">
              <form class="horizontal-form" autocomplete="off">
                <div class="m-form m-form--label-align-right">
                  <div class="row align-items-center m--margin-bottom-10">
                    <div class="col-xl-12">
                      <div class="form-group m-form__group align-items-center">
                        <div class="input-group">
                          <input
                            [(ngModel)]="filterText"
                            name="filterText"
                            autofocus
                            class="form-control m-input"
                            [placeholder]="l('SearchWithThreeDot')"
                            type="text"
                          />
                          <span class="input-group-btn">
                            <button
                              (click)="getMonths()"
                              class="btn btn-primary"
                              type="submit"
                            >
                              <i
                                class="flaticon-search-1"
                                [attr.aria-label]="l('Search')"
                              ></i>
                            </button>
                          </span>
                        </div>
                      </div>
                    </div>
                  </div>

                  <div
                    class="row margin-bottom-10"
                    *ngIf="advancedFiltersAreShown"
                  >
                    <div class="col-sm-12 text-right">
                      <button class="btn btn-metal" (click)="getMonths()">
                        <i class="fa fa-refresh"></i> {{ l("Refresh") }}
                      </button>
                    </div>
                  </div>
                  <div class="row margin-bottom-10">
                    <div class="col-sm-12">
                      <span
                        class="clickable-item text-muted"
                        *ngIf="!advancedFiltersAreShown"
                        (click)="
                          advancedFiltersAreShown = !advancedFiltersAreShown
                        "
                      >
                        <i class="fa fa-angle-down"></i>
                        {{ l("ShowAdvancedFilters") }}</span
                      >
                      <span
                        class="clickable-item text-muted"
                        *ngIf="advancedFiltersAreShown"
                        (click)="
                          advancedFiltersAreShown = !advancedFiltersAreShown
                        "
                      >
                        <i class="fa fa-angle-up"></i>
                        {{ l("HideAdvancedFilters") }}</span
                      >
                    </div>
                  </div>
                </div>
              </form>

              <div class="row align-items-center">
                <div
                  class="primeng-datatable-container"
                  [busyIf]="primengTableHelper.isLoading"
                >
                  <div class="m-month">
                    <div class="table-responsive" style="min-height: 600px">
                      <p-table
                        #dataTable
                        (onLazyLoad)="getMonths($event)"
                        [value]="primengTableHelper.records"
                        rows="{{
                          primengTableHelper.defaultRecordsCountPerPage
                        }}"
                        [paginator]="false"
                        [lazy]="true"
                        emptyMessage="没有数据"
                        scrollable="true"
                        ScrollWidth="100%"
                        responsive="primengTableHelper.isResponsive"
                        resizableColumns="primengTableHelper.resizableColumns"
                        dataKey="taskCode"
                      >
                        <ng-template pTemplate="header">
                          <tr>
                            <th style="width: 30px"></th>
                            <th
                              style="width: 130px"
                              *ngIf="
                                isGrantedAny(
                                  'Pages.Maintasks.Edit',
                                  'Pages.Maintasks.Delete',
                                  'Pages.Maintasks.PutInto',
                                  'Pages.Maintasks.Receive'
                                )
                              "
                            >
                              操作
                            </th>
                            <th style="width: 150px" pSortableColumn="taskCode">
                              任务号
                              <p-sortIcon field="taskCode"></p-sortIcon>
                            </th>
                            <th
                              style="width: 150px"
                              pSortableColumn="statusName"
                            >
                              状态
                              <p-sortIcon field="statusName"></p-sortIcon>
                            </th>
                            <th
                              style="width: 200px"
                              pSortableColumn="drawingCode"
                            >
                              图号
                              <p-sortIcon field="drawingCode"></p-sortIcon>
                            </th>
                            <th style="width: 200px" pSortableColumn="amount">
                              数量
                              <p-sortIcon field="amount"></p-sortIcon>
                            </th>
                            <th style="width: 150px" pSortableColumn="dueDate">
                              要求完成时间
                              <p-sortIcon field="dueDate"></p-sortIcon>
                            </th>

                            <th
                              style="width: 150px"
                              pSortableColumn="routingLine"
                            >
                              路线
                              <p-sortIcon field="routingLine"></p-sortIcon>
                            </th>
                            <th style="width: 150px" pSortableColumn="remark">
                              任务备注
                              <p-sortIcon field="remark"></p-sortIcon>
                            </th>
                          </tr>
                        </ng-template>
                        <ng-template
                          pTemplate="body"
                          let-record
                          let-expanded="expanded"
                        >
                          <tr>
                            <td style="width: 30px">
                              <a href="#" [pRowToggler]="record">
                                <i
                                  [ngClass]="
                                    expanded
                                      ? 'pi pi-chevron-down'
                                      : 'pi pi-chevron-right'
                                  "
                                ></i>
                              </a>
                            </td>
                            <td
                              style="width: 130px"
                              *ngIf="
                                isGrantedAny(
                                  'Pages.Maintasks.Edit',
                                  'Pages.Maintasks.Delete',
                                  'Pages.Maintasks.PutInto',
                                  'Pages.Maintasks.Receive'
                                )
                              "
                            >
                              <div
                                class="btn-group dropdown"
                                dropdown
                                container="body"
                              >
                                <button
                                  dropdownToggle
                                  class="dropdown-toggle btn btn-sm btn-primary"
                                >
                                  <i class="fa fa-cog"></i
                                  ><span class="caret"></span>
                                  操作
                                </button>
                                <ul class="dropdown-menu" *dropdownMenu>
                                  <li
                                    *ngIf="isGranted('Pages.Maintasks.PutInto')"
                                  >
                                    <a
                                      (click)="
                                        putIntoProductionModal.showMonth(
                                          record.taskId,
                                          record.id,
                                          $event
                                        )
                                      "
                                      >投产</a
                                    >
                                  </li>
                                </ul>
                              </div>
                            </td>
                            <td style="width: 150px">
                              <span class="ui-column-title"> 任务号</span>
                              {{ record.taskCode }}
                            </td>
                            <td style="width: 150px">
                              <span class="ui-column-title"> 状态</span>
                              <div
                                *ngIf="record.isComplete == false"
                                style="
                                  position: relative;
                                  text-align: center;
                                  width: 60px;
                                  border-radius: 2em;
                                  background-color: #f4516c;
                                  color: white;
                                "
                              >
                                <span class="badge">未完成</span>
                              </div>
                              <div
                                *ngIf="record.isComplete == true"
                                style="
                                  position: relative;
                                  text-align: center;
                                  width: 60px;
                                  border-radius: 2em;
                                  background-color: #34bfa3;
                                  color: white;
                                "
                              >
                                <span class="badge">已完成</span>
                              </div>
                            </td>
                            <td style="width: 200px">
                              <span class="ui-column-title"> 图号</span>
                              <!-- <ng-template  pTemplate="body"> -->
                              {{ record.drawingCode }}

                              <!-- </ng-template> -->
                            </td>
                            <td style="width: 200px">
                              <span class="ui-column-title"> 数量</span>
                              <!-- <ng-template pTemplate="body"> -->
                              <div class="row" style="margin: 0">
                                <div class="col-md-6" style="margin-top: 10px">
                                  <i class="icon-layers"></i>
                                  <span class="caption-subject bold font-ml">{{
                                    record.amount
                                  }}</span>
                                </div>
                                <div
                                  class="font-grey-cascade col-md-6 text-right"
                                >
                                  <div class="caption-subject font-green">
                                    交付:
                                    {{ record.amountFinished }}
                                  </div>
                                  <div class="font-grey-cascade">
                                    已投:
                                    {{ record.amountPlanned }}
                                  </div>
                                </div>
                              </div>
                              <!-- </ng-template> -->
                            </td>
                            <td style="width: 150px">
                              <span class="ui-column-title"> 要求完成时间</span>
                              {{ record.dueDate | momentFormat: "YYYY-MM-DD" }}
                            </td>

                            <td style="width: 150px">
                              <span class="ui-column-title"> 路线</span>
                              {{ record.routingLine }}
                            </td>
                            <td style="width: 150px">
                              <span class="ui-column-title"> 任务备注</span>
                              {{ record.remark }}
                            </td>
                          </tr>
                        </ng-template>
                        <ng-template pTemplate="rowexpansion" let-record>
                          <div
                            class="ui-grid ui-grid-responsive ui-fluid"
                            style="margin: -0.75em; padding: 20px"
                          >
                            <!-- <div class="ui-grid-row"> -->
                            <tr>
                              <td [attr.colspan]="11">
                                <p-table
                                  class="detailTable"
                                  [value]="record.getPipelineList"
                                  [paginator]="false"
                                  [lazy]="true"
                                  [scrollable]="true"
                                >
                                  <ng-template pTemplate="header">
                                    <tr>
                                      <th
                                        style="text-align: center; width: 200px"
                                      >
                                        投产任务号
                                      </th>
                                      <th
                                        style="text-align: center; width: 200px"
                                      >
                                        投产数量
                                      </th>
                                      <th
                                        style="text-align: center; width: 200px"
                                      >
                                        计划完成时间
                                      </th>
                                      <th
                                        style="text-align: center; width: 200px"
                                      >
                                        模板名称
                                      </th>
                                      <th
                                      style="text-align: center; width: 200px"
                                    >
                                      主制班组
                                    </th>
                                      <th
                                        style="text-align: center; width: 200px"
                                      >
                                        合格证号
                                      </th>
                                      <th
                                        style="text-align: center; width: 200px"
                                      >
                                        质控卡号
                                      </th>
                                    </tr>
                                  </ng-template>
                                  <ng-template pTemplate="body" let-rowData>
                                    <tr [pSelectableRow]="rowData">
                                      <td
                                        style="text-align: center; width: 200px"
                                      >
                                        {{ rowData.batchCode }}
                                      </td>
                                      <td
                                        style="text-align: center; width: 200px"
                                      >
                                        {{ rowData.amountPlanned }}
                                      </td>
                                      <td
                                        style="text-align: center; width: 200px"
                                      >
                                        {{
                                          rowData.dueDatePlanned
                                            | momentFormat: "YYYY-MM-DD"
                                        }}
                                      </td>

                                      <td
                                        style="text-align: center; width: 200px"
                                      >
                                        {{ rowData.taskTypeName }}
                                      </td>
                                      <td
                                      style="text-align: center; width: 200px"
                                    >
                                      {{ rowData.mainTeamGroup }}
                                    </td>
                                      <td
                                        style="text-align: center; width: 200px"
                                      >
                                        {{ rowData.hgzNo }}
                                      </td>
                                      <td
                                        style="text-align: center; width: 200px"
                                      >
                                        {{ rowData.zhikongkaNo }}
                                      </td>
                                    </tr>
                                  </ng-template>
                                </p-table>
                              </td>
                            </tr>
                            <!-- </div> -->
                          </div>
                        </ng-template>
                      </p-table>
                      <div class="primeng-paging-container">
                        <p-paginator
                          rows="{{
                            primengTableHelper.defaultRecordsCountPerPage
                          }}"
                          #paginator
                          (onPageChange)="getMonths($event)"
                          [totalRecords]="primengTableHelper.totalRecordsCount"
                          [rowsPerPageOptions]="
                            primengTableHelper.predefinedRecordsCountPerPage
                          "
                        >
                        </p-paginator>
                        <span class="total-records-count">
                          {{ "总计:" + primengTableHelper.totalRecordsCount }}
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <putIntoProductionModal
    #putIntoProductionModal
    (modalSave)="getMonths($event)"
  ></putIntoProductionModal>
</div>
